/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hutech09.jsale.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author Nam
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Producttype.findAll", query = "SELECT p FROM ProductType p"),
    @NamedQuery(name = "Producttype.findById", query = "SELECT p FROM ProductType p WHERE p.id = :id"),
    @NamedQuery(name = "Producttype.findByName", query = "SELECT p FROM ProductType p WHERE p.name = :name"),
    @NamedQuery(name = "Producttype.findByCategory", query = "SELECT p FROM ProductType p WHERE p.category = :category")})
public class ProductType implements ICommonEntity, Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(length = 40)
    private String name;
    
    @ManyToOne
    @JoinColumn(nullable = false)
    private Category category;
//
//        @Column(name = "CATEGORY_ID")
//    private Long cateID;
    
    @OneToMany(cascade = CascadeType.ALL,orphanRemoval = true)
   @JoinColumn(name = "PRODUCTTYPE_ID",referencedColumnName = "id") 
     private List<Product> listProduct = new ArrayList<Product>();

    public List<Product> getListProduct() {
        return listProduct;
    }

    public void setListProduct(List<Product> listProduct) {
        this.listProduct = listProduct;
    }
     
    public ProductType() {
    }

    public ProductType(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    } 

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProductType)) {
            return false;
        }
        ProductType other = (ProductType) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.hutech09.entity.ProductType[ id=" + id + " ]";
    }
}
